package com.common.interceptor;

import java.lang.reflect.Method;
import java.util.UUID;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.ThrowsAdvice;

import com.common.base.exceptions.DaoException;
import com.opensymphony.xwork2.ActionContext;

public class ExceptionAdvice implements ThrowsAdvice {

	protected final Log logger = LogFactory.getLog(this.getClass());

	// 异常拦截器
	public void afterThrowing(Method method, Object[] args, Object instance,
			Exception e) throws Throwable {

//		String uuid = UUID.randomUUID().toString();

		if (e instanceof DaoException) {
		//	System.out.println("Dao异常");
		} else {
		//	System.out.println("其他异常");
		}
		System.out.println("---------------------------------------------------------------#########");
		logger.error("ClassName:    "+ instance.getClass().getName());
		logger.error("MethodName:   " + method.getName());
		logger.error("ErrorMessage: " + e.getMessage());
		logger.error("ErrorCause:   " + e.getCause());
	}

	/*
	 *  方法二
	 *  public void afterThrowing(NullPointerException ex) throws Throwable {}
	 * */
}
